﻿Public Class frmSubSach
    Private MaSach As String
    Private TenSach As String
    Private oldMaTG As String
    Public Sub TruyenThamSo(ByVal MS As String, ByVal TS As String)
        MaSach = MS
        TenSach = TS
    End Sub
    Private Sub frmSubSach_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        datSubSach.DataSource = db.QueryTable("select st.MaTG,TenTG,ghichu from sach_tacgia st inner join tacgia t on t.matg=st.matg where masach='" & MaSach & "'")
        Text = TenSach
        cboTenTG.DisplayMember = "TenTG"
        cboTenTG.ValueMember = "MaTG"
        cboTenTG.DataSource = db.QueryTable("select * from TacGia")

    End Sub

    Private Sub btnTheamTG_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThemTG.Click


        clsSubSach.ThemTG(cboTenTG.SelectedValue, MaSach, txtGhiChu.Text)
        datSubSach.DataSource = db.QueryTable("select st.MaTG,TenTG,ghichu from sach_tacgia st inner join tacgia t on t.matg=st.matg where masach='" & MaSach & "'")
    End Sub

    Private Sub btnXoaTG_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXoaTG.Click
        clsSubSach.XoaTG(MaSach, cboTenTG.SelectedValue)
        datSubSach.DataSource = db.QueryTable("select st.MaTG,TenTG,ghichu from sach_tacgia st inner join tacgia t on t.matg=st.matg where masach='" & MaSach & "'")

    End Sub

   

    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        Me.Close()
    End Sub

    Private Sub btnSua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSua.Click
        oldMaTG = datSubSach.CurrentRow.Cells("MaTG").Value
        clsSubSach.SuaTG(cboTenTG.SelectedValue, MaSach, txtGhiChu.Text, oldMaTG) 'sao lai viet code the nay :|
        datSubSach.DataSource = db.QueryTable("select TenTG,ghichu from sach_tacgia st inner join tacgia t on t.matg=st.matg where masach='" & MaSach & "'")

    End Sub

    Private Sub datSubSach_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles datSubSach.CellDoubleClick

        txtGhiChu.Text = datSubSach.CurrentRow.Cells("GhiChu").Value
        cboTenTG.Text = datSubSach.CurrentRow.Cells("TenTG").Value
    End Sub
End Class